package com.login;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {

	private Connection connection=null;
	private String urlDb;//数据库
	private String user;//用户名
	private String password;//密码
	public DBUtil(){
		
	}
	 Connection getConnection()
	 {
	     urlDb="jdbc:mysql://localhost:3306/java";//java是数据库名字
	     user="root";
	     try
	     {
	         Class.forName("com.mysql.jdbc.Driver");
	     }catch (ClassNotFoundException  e) {
	         e.printStackTrace();
	    } 
	     try
	     {
	         connection=DriverManager.getConnection(urlDb, user, password);//连接数据库
	     }catch (SQLException e) {
	         e.printStackTrace();
	    }
	     return connection;
	 }
	
}
